# Maintainer: Ray Donnelly <mingw.android@gmail.com>
# Maintainer (ArchLinux): Andrzej Giniewicz <gginiu@gmail.com>
# Contributor (ArchLinux): Cristóvão D. Sousa <crisjss@gmail.com>

_realname=dsdp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.8
pkgrel=1
pkgdesc="A free open source implementation of an interior-point method for semidefinite programming (mingw-w64)"
arch=('any')
url="https://www.mcs.anl.gov/hs/software/DSDP"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-openblas")
source=("http://www.mcs.anl.gov/hs/software/${_realname^^}/${_realname^^}${pkgver}.tar.gz")
#        "make.include.patch")
sha256sums=('26aa624525a636de272c0b329e2dfd01a0d5b7827f1c1c76f393d71e37dead70')

prepare () {
  cd "${srcdir}"

  [[ -d build-${CARCH} ]] && rm -rf build-${CARCH}
  cp -rf ${_realname^^}${pkgver} build-${CARCH}
  cd build-${CARCH}
  sed -i 's|-llapack||g' make.include
  sed -i 's|-lblas|-lopenblas|g' make.include
  sed -i 's|-lg2c|-lgfortran|g' make.include
#  patch -p1 -i "${srcdir}"/make.include.patch
}

build() {
  cd "${srcdir}"/build-${CARCH}

  make DSDPROOT="${PWD}" dsdpapi
}

package() {
  cd "${srcdir}"/build-${CARCH}

  install -d "${pkgdir}"${MINGW_PREFIX}/{lib,include/dsdp}
  install -Dm755 bin/dsdp5 "${pkgdir}"${MINGW_PREFIX}/bin/dsdp5
  install -Dm644 lib/* "${pkgdir}"${MINGW_PREFIX}/lib/
  install -Dm644 include/*.h "${pkgdir}"${MINGW_PREFIX}/include/dsdp/
  install -Dm644 dsdp-license "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/dsdp-license
}
